package com.shop.product.controller;

import com.shop.common.core.domain.Result;
import com.shop.common.core.web.controller.BaseController;
import com.shop.common.core.web.page.TableDataInfo;
import com.shop.common.log.annotation.Log;
import com.shop.common.log.enums.BusinessType;
import com.shop.common.security.annotation.RequiresPermissions;

import com.shop.product.domain.MallProductTypeInfo;
import com.shop.product.domain.res.MallProductTypeInfoVo;
import com.shop.product.service.MallProductTypeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productTypeInfo")
public class MallProductTypeInfoController extends BaseController {
    @Autowired
    MallProductTypeInfoService mallProductTypeInfoService;

    /**
     * 查询商品三级分类列表
     * @param mallProductTypeInfo
     * @return
     */
    @RequiresPermissions("product:productTypeInfo:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(MallProductTypeInfo mallProductTypeInfo){
        startPage();
        List<MallProductTypeInfo> list= mallProductTypeInfoService.selectMallProductTypeInfoList(mallProductTypeInfo);
        return getDataTable(list);
    }

    /**
     * 获取商品三级分类详情信息
     * @param catId
     * @return
     */
    @RequiresPermissions("product:productTypeInfo:query")
    @GetMapping(value = "/{carId}")
    public Result getInfo(@PathVariable("catId") Long catId){
        return success(mallProductTypeInfoService.selectMallProductTypeInfoByCatId(catId));
    }

    /**
     * 新增商品三级分类
     * @param mallProductTypeInfo
     * @return
     */
    @RequiresPermissions("product:productTypeInfo:add")
    @Log(title = "商品三级分类", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody MallProductTypeInfo mallProductTypeInfo){
        return toAjax(mallProductTypeInfoService.insertMallProductTypeInfo(mallProductTypeInfo));
    }

    /**
     * 修改商品三级分类
     */
    @RequiresPermissions("product:productTypeInfo:edit")
    @Log(title = "商品三级分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody MallProductTypeInfo mallProductTypeInfo)
    {
        return toAjax(mallProductTypeInfoService.updateMallProductTypeInfo(mallProductTypeInfo));
    }

    /**
     * 删除商品三级分类
     */
    @RequiresPermissions("shop:productTypeInfo:remove")
    @Log(title = "商品三级分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{catIds}")
    public Result remove(@PathVariable Long[] catIds)
    {
        return toAjax(mallProductTypeInfoService.deleteMallProductTypeInfoByCatIds(catIds));
    }

    @GetMapping("/listAll")
    public Result<List<MallProductTypeInfoVo>> listAll(MallProductTypeInfo mallProductTypeInfo){

        List<MallProductTypeInfoVo> list=mallProductTypeInfoService.listAll(mallProductTypeInfo);

        return Result.success(list);
    }

    @GetMapping("/listAll1")
    private Result<List<MallProductTypeInfoVo>> listAll1(MallProductTypeInfo mallProductTypeInfo){
        startPage();
        List<MallProductTypeInfoVo>list=mallProductTypeInfoService.listAll1(mallProductTypeInfo);
        return Result.success(list);
    }
}
